iT邦幫忙

2022 iThome 鐵人賽

DAY 4
0
Software Development

ClickHouse:時序資料庫建置與運行系列 第 4

day4-介紹ClickHouse安裝方法(中)

  • 分享至 

  • xImage
  •  

前言

上一章節中,我們展示了在RPM與DEB為基礎的Linux散布作業系統版本上安裝ClickHouse資料庫與客戶端的指令,本章節,我們將會繼續演示其他的ClickHouse資料庫與客戶端的安裝方式。

方法3:使用Tgz壓縮檔安裝

如果目的的作業系統上,沒有RPM與DEB的方式來安裝ClickHouse資料庫與相關套件的話,則官方建議可以使用官方已經預先編譯好的Tgz壓縮檔來安裝ClickHouse資料庫伺服器與客戶端程式。

首先,先需要有curl或是wget指令來下載相關的壓縮檔,放置壓縮檔的儲存庫網址在這裡: https://packages.clickhouse.com/tgz

下面是安裝目前最新穩定(stable)版本的範例腳本:

LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
    grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
export LATEST_VERSION

case $(uname -m) in
  x86_64) ARCH=amd64 ;;
  aarch64) ARCH=arm64 ;;
  *) echo "Unknown architecture $(uname -m)"; exit 1 ;;
esac

for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
do
  curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
    || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
done

tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server start

tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"

從上述的腳本來看,首先會使用curlgrep指令找到遠端ClickHouse儲存庫目前最新穩定版本號,接著使用uname -m指令找到當前此作業系統的機器所使用的CPU架構,若架構不是x86_64或aarch64,則會輸出未知架構訊息出來並將離開碼設定為1,表示腳本執行到錯誤地方跳出。

接著使用Bash的for迴圈依序的下載clickhouse-common-staticclickhouse-common-static-dbgclickhouse-serverclickhouse-client等壓縮檔。

等到上面的迴圈都把需要下載的壓縮檔都下載完成之後,接著依序的將這些壓縮檔進行解壓縮並執行裡面有的doinst.sh的腳本,同時在clickhouse-server完成安裝後,會順便執行sudo /etc/init.d/clickhouse-server start將ClickHouse資料庫伺服器進行啟動。這樣一來就完成以預先編譯好的壓縮檔的安裝方式了。

我們以一個乾淨的Ubuntu 18.04的Linux發行版本的作業系統來操作上面的安裝過程。首先使用vim clickhouse_tgz.sh指令打開編輯器,並按下「i」鍵,將上述的腳本內容貼上去,接著按下ESC鍵並輸入「:wq」之後,這樣就會存成名叫clickhouse_tgz.sh的腳本檔案,接著執行chmod +x clickhouse_tgz.sh將此腳本檔案的權限改成可執行的權限,最後執行sudo ./clickhouse_tgz.sh指令來執行上述的腳本,上述相關的指令與輸出的訊息如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ vim clickhouse_tgz.sh
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ cat clickhouse_tgz.sh
LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \
    grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
export LATEST_VERSION

case $(uname -m) in
  x86_64) ARCH=amd64 ;;
  aarch64) ARCH=arm64 ;;
  *) echo "Unknown architecture $(uname -m)"; exit 1 ;;
esac

for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
do
  curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
    || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
done

tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server start

tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
  || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ chmod +x clickhouse_tgz.sh
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo ./clickhouse_tgz.sh
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo ./clickhouse_tgz.sh
[sudo] password for peter:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  237M  100  237M    0     0  76.9M      0  0:00:03  0:00:03 --:--:-- 76.9M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  818M  100  818M    0     0  16.7M      0  0:00:48  0:00:48 --:--:-- 19.4M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 94371  100 94371    0     0   208k      0 --:--:-- --:--:-- --:--:--  208k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 71815  100 71815    0     0   177k      0 --:--:-- --:--:-- --:--:--  177k
clickhouse-common-static-22.8.4.7/
clickhouse-common-static-22.8.4.7/usr/
clickhouse-common-static-22.8.4.7/usr/bin/
clickhouse-common-static-22.8.4.7/usr/bin/clickhouse-odbc-bridge
clickhouse-common-static-22.8.4.7/usr/bin/clickhouse-extract-from-config
clickhouse-common-static-22.8.4.7/usr/bin/clickhouse-library-bridge
clickhouse-common-static-22.8.4.7/usr/bin/clickhouse
clickhouse-common-static-22.8.4.7/usr/bin/clickhouse-diagnostics
clickhouse-common-static-22.8.4.7/usr/share/
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/completions/
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/completions/clickhouse-client
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/completions/clickhouse-bootstrap
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/completions/clickhouse-benchmark
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/completions/clickhouse-local
clickhouse-common-static-22.8.4.7/usr/share/bash-completion/completions/clickhouse
clickhouse-common-static-22.8.4.7/usr/share/doc/
clickhouse-common-static-22.8.4.7/usr/share/doc/clickhouse-common-static/
clickhouse-common-static-22.8.4.7/usr/share/doc/clickhouse-common-static/CHANGELOG.md
clickhouse-common-static-22.8.4.7/usr/share/doc/clickhouse-common-static/AUTHORS
clickhouse-common-static-22.8.4.7/usr/share/doc/clickhouse-common-static/LICENSE
clickhouse-common-static-22.8.4.7/usr/share/doc/clickhouse-common-static/README.md
clickhouse-common-static-22.8.4.7/install/
clickhouse-common-static-22.8.4.7/install/doinst.sh
clickhouse-common-static-dbg-22.8.4.7/
clickhouse-common-static-dbg-22.8.4.7/usr/
clickhouse-common-static-dbg-22.8.4.7/usr/lib/
clickhouse-common-static-dbg-22.8.4.7/usr/lib/debug/
clickhouse-common-static-dbg-22.8.4.7/usr/lib/debug/usr/
clickhouse-common-static-dbg-22.8.4.7/usr/lib/debug/usr/bin/
clickhouse-common-static-dbg-22.8.4.7/usr/lib/debug/usr/bin/clickhouse-library-bridge.debug
clickhouse-common-static-dbg-22.8.4.7/usr/lib/debug/usr/bin/clickhouse.debug
clickhouse-common-static-dbg-22.8.4.7/usr/lib/debug/usr/bin/clickhouse-odbc-bridge.debug
clickhouse-common-static-dbg-22.8.4.7/usr/share/
clickhouse-common-static-dbg-22.8.4.7/usr/share/doc/
clickhouse-common-static-dbg-22.8.4.7/usr/share/doc/clickhouse-common-static-dbg/
clickhouse-common-static-dbg-22.8.4.7/usr/share/doc/clickhouse-common-static-dbg/CHANGELOG.md
clickhouse-common-static-dbg-22.8.4.7/usr/share/doc/clickhouse-common-static-dbg/AUTHORS
clickhouse-common-static-dbg-22.8.4.7/usr/share/doc/clickhouse-common-static-dbg/LICENSE
clickhouse-common-static-dbg-22.8.4.7/usr/share/doc/clickhouse-common-static-dbg/README.md
clickhouse-common-static-dbg-22.8.4.7/install/
clickhouse-common-static-dbg-22.8.4.7/install/doinst.sh
clickhouse-server-22.8.4.7/
clickhouse-server-22.8.4.7/usr/
clickhouse-server-22.8.4.7/usr/bin/
clickhouse-server-22.8.4.7/usr/bin/clickhouse-report
clickhouse-server-22.8.4.7/usr/bin/clickhouse-server
clickhouse-server-22.8.4.7/usr/bin/clickhouse-keeper
clickhouse-server-22.8.4.7/usr/bin/clickhouse-copier
clickhouse-server-22.8.4.7/usr/share/
clickhouse-server-22.8.4.7/usr/share/doc/
clickhouse-server-22.8.4.7/usr/share/doc/clickhouse-server/
clickhouse-server-22.8.4.7/usr/share/doc/clickhouse-server/CHANGELOG.md
clickhouse-server-22.8.4.7/usr/share/doc/clickhouse-server/AUTHORS
clickhouse-server-22.8.4.7/usr/share/doc/clickhouse-server/LICENSE
clickhouse-server-22.8.4.7/usr/share/doc/clickhouse-server/README.md
clickhouse-server-22.8.4.7/lib/
clickhouse-server-22.8.4.7/lib/systemd/
clickhouse-server-22.8.4.7/lib/systemd/system/
clickhouse-server-22.8.4.7/lib/systemd/system/clickhouse-server.service
clickhouse-server-22.8.4.7/install/
clickhouse-server-22.8.4.7/install/doinst.sh
clickhouse-server-22.8.4.7/etc/
clickhouse-server-22.8.4.7/etc/init.d/
clickhouse-server-22.8.4.7/etc/init.d/clickhouse-server
clickhouse-server-22.8.4.7/etc/clickhouse-server/
clickhouse-server-22.8.4.7/etc/clickhouse-server/config.xml
clickhouse-server-22.8.4.7/etc/clickhouse-server/users.xml
ClickHouse binary is already located at /usr/bin/clickhouse
Symlink /usr/bin/clickhouse-server already exists but it points to /home/peter/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-copier already exists but it points to /home/peter/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-extract-from-config already exists but it points to /home/peter/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper already exists but it points to /home/peter/clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
 groupadd -r clickhouse
Creating clickhouse user if it does not exist.
 useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Config file /etc/clickhouse-server/config.xml already exists, will keep it and extract path info from it.
/etc/clickhouse-server/config.xml has /var/lib/clickhouse/ as data path.
/etc/clickhouse-server/config.xml has /var/log/clickhouse-server/ as log path.
Users config file /etc/clickhouse-server/users.xml already exists, will keep it and extract users info from it.
Creating log directory /var/log/clickhouse-server/.
Creating data directory /var/lib/clickhouse/.
Creating pid directory /var/run/clickhouse-server.
 chown -R clickhouse:clickhouse '/var/log/clickhouse-server/'
 chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
 chown  clickhouse:clickhouse '/var/lib/clickhouse/'
 groupadd -r clickhouse-bridge
 useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse-bridge clickhouse-bridge
 chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-odbc-bridge'
 chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-library-bridge'
Enter password for default user:
Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
Setting capabilities for clickhouse binary. This is optional.
Cannot set 'net_admin' or 'ipc_lock' or 'sys_nice' or 'net_bind_service' capability for clickhouse binary. This is optional. Taskstats accounting will be disabled. To enable taskstats accounting you may add the required capability later manually.
 chown -R clickhouse:clickhouse '/etc/clickhouse-server'

ClickHouse has been successfully installed.

Start clickhouse-server with:
 sudo clickhouse start

Start clickhouse-client with:
 clickhouse-client --password

Synchronizing state of clickhouse-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable clickhouse-server
 chown -R clickhouse: '/var/run/clickhouse-server/'
Will run clickhouse su 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
Waiting for server to start
Waiting for server to start
Server started
sed: can't read /etc/cron.d/clickhouse-server: No such file or directory
clickhouse-client-22.8.4.7/
clickhouse-client-22.8.4.7/usr/
clickhouse-client-22.8.4.7/usr/bin/
clickhouse-client-22.8.4.7/usr/bin/clickhouse-client
clickhouse-client-22.8.4.7/usr/bin/clickhouse-benchmark
clickhouse-client-22.8.4.7/usr/bin/clickhouse-local
clickhouse-client-22.8.4.7/usr/bin/clickhouse-format
clickhouse-client-22.8.4.7/usr/bin/clickhouse-obfuscator
clickhouse-client-22.8.4.7/usr/bin/clickhouse-compressor
clickhouse-client-22.8.4.7/usr/share/
clickhouse-client-22.8.4.7/usr/share/doc/
clickhouse-client-22.8.4.7/usr/share/doc/clickhouse-client/
clickhouse-client-22.8.4.7/usr/share/doc/clickhouse-client/CHANGELOG.md
clickhouse-client-22.8.4.7/usr/share/doc/clickhouse-client/AUTHORS
clickhouse-client-22.8.4.7/usr/share/doc/clickhouse-client/LICENSE
clickhouse-client-22.8.4.7/usr/share/doc/clickhouse-client/README.md
clickhouse-client-22.8.4.7/install/
clickhouse-client-22.8.4.7/install/doinst.sh
clickhouse-client-22.8.4.7/etc/
clickhouse-client-22.8.4.7/etc/clickhouse-client/
clickhouse-client-22.8.4.7/etc/clickhouse-client/config.xml

從上面指令輸出的結果訊息來看,我們可以知道與使用DEB或是RPM進行安裝上沒有什麼區別,其中會有「Enter password for default user:」來對預設使用者default來設定密碼。

上述的腳本執行完成之後,可以使用ls指令來列出所有在這個腳本執行中所下載的壓縮檔,相關的指令執行與輸出的結果如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ ls
clickhouse-client-22.8.4.7                   clickhouse-common-static-dbg-22.8.4.7-amd64.tgz
clickhouse-client-22.8.4.7-amd64.tgz         clickhouse-server-22.8.4.7
clickhouse-common-static-22.8.4.7            clickhouse-server-22.8.4.7-amd64.tgz
clickhouse-common-static-22.8.4.7-amd64.tgz  clickhouse_tgz.sh
clickhouse-common-static-dbg-22.8.4.7
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

方法4:使用Docker Image進行安裝

我們也可以使用官方所建置好的Docker image映像來進行ClickHouse資料庫與客戶端的安裝,Docker的映像檔可以參考此網址:https://hub.docker.com/r/clickhouse/clickhouse-server。

在使用ClickHouse的Docker映像檔之前,需要先在目的的作業系統上將Docker相關的指令安裝好,我們使用Ubuntu 18.04的Linux發布版本的作業系統進行示範,相關的指令執行如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo apt-get update
[sudo] password for peter:
Get:1 http://mirrors.digitalocean.com/ubuntu bionic InRelease [242 kB]
Get:2 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease [88.7 kB]
Hit:3 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease
Get:4 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://mirrors.digitalocean.com/ubuntu bionic-updates/main amd64 Packages [2729 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:7 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Translation-en [503 kB]
Get:8 http://mirrors.digitalocean.com/ubuntu bionic-updates/restricted amd64 Packages [913 kB]
Get:9 http://mirrors.digitalocean.com/ubuntu bionic-updates/restricted Translation-en [126 kB]
Get:10 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe amd64 Packages [1842 kB]
Get:11 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Translation-en [399 kB]
Get:12 http://mirrors.digitalocean.com/ubuntu bionic-updates/multiverse amd64 Packages [24.9 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2389 kB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [414 kB]
Get:15 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [884 kB]
Get:16 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [122 kB]
Get:17 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1228 kB]
Get:18 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [282 kB]
Get:19 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [19.0 kB]
Fetched 12.4 MB in 6s (2230 kB/s)
Reading package lists... Done
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo apt-get install curl apt-transport-https ca-certificates software-properties-common -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20211016~18.04.1).
software-properties-common is already the newest version (0.96.24.32.18).
software-properties-common set to manually installed.
apt-transport-https is already the newest version (1.6.14).
The following additional packages will be installed:
  libcurl4
The following packages will be upgraded:
  curl libcurl4
2 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.
Need to get 379 kB of archives.
After this operation, 0 B of additional disk space will be used.
......
Setting up libcurl4:amd64 (7.58.0-2ubuntu3.20) ...
Setting up curl (7.58.0-2ubuntu3.20) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:2 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease
Get:3 http://mirrors.digitalocean.com/ubuntu bionic InRelease [242 kB]
Hit:4 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease
Hit:5 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease
Hit:6 http://security.ubuntu.com/ubuntu bionic-security InRelease
Fetched 242 kB in 1s (416 kB/s)
Reading package lists... Done
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo apt-get install -y docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  containerd.io docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libltdl7 pigz
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
Recommended packages:
  slirp4netns
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libltdl7 pigz
0 upgraded, 7 newly installed, 0 to remove and 23 not upgraded.
Need to get 102 MB of archives.
After this operation, 422 MB of additional disk space will be used.
Get:1 http://mirrors.digitalocean.com/ubuntu bionic/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 containerd.io amd64 1.6.8-1 [28.1 MB]
Get:3 http://mirrors.digitalocean.com/ubuntu bionic/main amd64 libltdl7 amd64 2.4.6-2 [38.8 kB]
Get:4 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-cli amd64 5:20.10.17~3-0~ubuntu-bionic [40.6 MB]
Get:5 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:20.10.17~3-0~ubuntu-bionic [21.0 MB]
Get:6 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-rootless-extras amd64 5:20.10.17~3-0~ubuntu-bionic [8163 kB]
Get:7 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-bionic [3521 kB]
Fetched 102 MB in 2s (55.9 MB/s)
Selecting previously unselected package pigz.
(Reading database ... 60519 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.6.8-1_amd64.deb ...
Unpacking containerd.io (1.6.8-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.17~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.17~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.17~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce (5:20.10.17~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.17~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../5-docker-scan-plugin_0.17.0~ubuntu-bionic_amd64.deb ...
Unpacking docker-scan-plugin (0.17.0~ubuntu-bionic) ...
Selecting previously unselected package libltdl7:amd64.
Preparing to unpack .../6-libltdl7_2.4.6-2_amd64.deb ...
Unpacking libltdl7:amd64 (2.4.6-2) ...
Setting up containerd.io (1.6.8-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-bionic) ...
Setting up docker-scan-plugin (0.17.0~ubuntu-bionic) ...
Setting up libltdl7:amd64 (2.4.6-2) ...
Setting up docker-ce-cli (5:20.10.17~3-0~ubuntu-bionic) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce (5:20.10.17~3-0~ubuntu-bionic) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
Processing triggers for systemd (237-3ubuntu10.53) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo systemctl enable --now docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2022-09-07 10:58:38 UTC; 35s ago
     Docs: https://docs.docker.com
 Main PID: 4200 (dockerd)
    Tasks: 10
   CGroup: /system.slice/docker.service
           └─4200 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

從上述的指令可以得知,首先更新鏡像,接著先將一些需要的套件安裝好,接著使用curl指令將Docker官方給Ubuntu的GPG金鑰匯入到本地端GPG金鑰庫,接著因為本地機器是64位元的架構,因此使用add-apt-repository指令將deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable的鏡像位址寫入到/etc/apt/sources.list檔案中,接著就可以執行sudo apt-get install docker-ce -y把Docker給安裝起來了。

在安裝好Docker之後,接著再使用sudo systemctl enable --now docker指令,確認Docker服務現在已經啟動並設定開機之後會自動啟動,同時使用sudo systemctl status docker.service指令來確認目前Docker的服務狀態。

安裝好Docker之後,接下來可以執行sudo docker pull clickhouse/clickhouse-server指令將ClickHouse的資料庫給下載回來,相關的指令執行與輸出的結果如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker pull clickhouse/clickhouse-server
Using default tag: latest
latest: Pulling from clickhouse/clickhouse-server
3b65ec22a9e9: Pull complete
0f34bf5344ae: Pull complete
42403700dab1: Pull complete
05d784aed294: Pull complete
411bb232d640: Pull complete
cfd5c26333e1: Pull complete
e2be87f8d15b: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:128b5d3895380ff95c9cf9b83929596315586ad6ad9daa4f6dc5285b5c0a72ba
Status: Downloaded newer image for clickhouse/clickhouse-server:latest
docker.io/clickhouse/clickhouse-server:latest
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

在docker指令中,如果指定的Docker映像沒有設定標籤tag名稱的話,則會使用latest作為標籤名稱,若要指定下載的版本,則可以使用下列的指令來做到,相關的指令執行的方式與輸出的訊息如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker pull clickhouse/clickhouse-server:22.8.4.7
22.8.4.7: Pulling from clickhouse/clickhouse-server
3b65ec22a9e9: Already exists
0f34bf5344ae: Already exists
7f1fa49737e6: Pull complete
e42e1584caa8: Pull complete
54d7ab6a1060: Pull complete
f20b16288bbf: Pull complete
e2be87f8d15b: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:e049c36881ca4d56ef0c2fd3ed142962bb67d37d5b509f0f5b8e02a249a5a23e
Status: Downloaded newer image for clickhouse/clickhouse-server:22.8.4.7
docker.io/clickhouse/clickhouse-server:22.8.4.7
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

從上述的輸出訊息可以得知,可以使用:並在後面接上釋出的版本來指定要下載的ClickHouse資料庫的Docker映像檔,像上面的輸出訊息為例,就是指定22.8.4.7這個版本。

接著,使用下列的指令將ClickHouse資料庫啟動成Docker容器,相關的指令與輸出的訊息如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
df4cd2ace98a23b9f307aaae93ababe5cda20f5d26ccf0d82b30e4cfa2190861
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker ps
CONTAINER ID   IMAGE                          COMMAND            CREATED          STATUS          PORTS                          NAMES
df4cd2ace98a   clickhouse/clickhouse-server   "/entrypoint.sh"   13 seconds ago   Up 11 seconds   8123/tcp, 9000/tcp, 9009/tcp   some-clickhouse-server
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

若要使用ClickHouse自帶的客戶端指令,則可以使用下列兩個指令,這兩個指令皆可以達成使用ClickHouse的客戶端連上ClickHouse資料庫,相關的指令執行與輸出的訊息如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker exec -it some-clickhouse-server clickhouse-client
ClickHouse client version 22.8.4.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.

Warnings:
 * Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource

df4cd2ace98a :)

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker run -it --rm --link some-clickhouse-server:clickhouse-server --entrypoint clickhouse-client clickhouse/clickhouse-server --host clickhouse-server
ClickHouse client version 22.8.4.7 (official build).
Connecting to clickhouse-server:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.

Warnings:
 * Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource

df4cd2ace98a :)

從上面輸出的訊息可以知道,Docker映像檔的ClickHouse資料庫,其預設使用者default的密碼是空的。

若要停止或是重新啟動ClickHouse資料庫的Docker容器,則可以使用下列的指令,相關執行指令輸出的訊息如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker stop some-clickhouse-server
some-clickhouse-server
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker rm some-clickhouse-server
some-clickhouse-server
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

在網路設定的部分,因為ClickHouse資料庫需要有90048123之埠號進行存取資料庫,可以指定特定的埠號來綁定在主體host埠號上,相關的指令執行與輸出的結果如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker run -d -p 18123:8123 -p19000:9000 --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
9fde0d0e45d2174bd81baf9deb6eab7d884788c5f03e3e6c6390398b556909ee
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ echo 'SELECT version()' | curl 'http://localhost:18123/' --data-binary @-
22.8.4.7
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

當然,也可以使用主體的網路,直接讓將90048123的埠號綁定在主體host機器的埠號上,相關的執行指令與輸出的結果如下:

peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ sudo docker run -d --network=host --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
9fde0d0e45d2174bd81baf9deb6eab7d884788c5f03e3e6c6390398b556909ee
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$ echo 'SELECT version()' | curl 'http://localhost:8123/' --data-binary @-
22.8.4.7
peter@ubuntu-s-4vcpu-8gb-intel-sgp1-01:~$

至於儲存volumes,ClickHouse資料庫在啟動時候,會有下列兩個資料夾進行存取:

  • /var/lib/clickhouse/ - 為ClickHouse資料庫主要存取的資料夾,用來存放資料的地方
  • /val/log/clickhouse-server/ - ClickHouse資料庫運行的日誌記錄

我們可以使用下列的指令將上述兩個資料夾掛載到主體host上,並讓這些檔案永久的儲存在主體host的硬碟上,不會隨著ClickHouse資料庫的Docker容器停止運作而跟著消失:

sudo docker run -d \
	-v $(realpath ./ch_data):/var/lib/clickhouse/ \
	-v $(realpath ./ch_logs):/var/log/clickhouse-server/ \
	--name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server

同時,我們也有可能在啟動ClickHouse資料庫Docker容器的時候,需要掛載下列這幾個檔案或目錄:

  • /etc/clickhouse-server/config.d/*.xml - ClickHouse資料庫所需要的設定檔案
  • /etc/clickhouse-server/users.d/*.xml - ClickHouse使用者相關設定檔案
  • /docker-entrypoint-initdb.d/ - ClickHouse資料庫初始化啟動時的腳本

結論

在本章節中,我們展示了使用預先編譯好的ClickHouse資料庫壓縮檔以及使用ClickHouse的Docker映像檔來進行安裝,還有基本的啟動ClickHouse的Docker映像檔需要注意的用法與設定。在下一章節中,將會介紹如何使用單一二進位元執行檔與給非標準環境使用的預先編譯好的二進位元執行檔等方式安裝與使用ClickHouse資料庫。

參考資料


上一篇
day3-介紹ClickHouse安裝方法(上)
下一篇
day5-介紹ClickHouse安裝方法(下)
系列文
ClickHouse:時序資料庫建置與運行30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言